<?php
namespace app\admin\controller;

use app\common\logic\Logic;
use think\Db;


class Emoticon extends Base
{

    function _initialize()
    {
        parent::_initialize();
        $this->assign('stamp',123);
    }

    public function index()
    {
        $where = [];
        if(!empty($_GET['title'])){
            $where['b.title'] = ['like','%'.trim(input('get.title')).'%'];
        }
        if(!empty($_GET['cid'])){
            $where['b.cid'] = trim(input('get.cid'));
        }
        if(!isEmpty($_GET['status'])){
            $where['b.status'] = trim(input('get.status'));
        }
        $model = new \app\common\model\Emoticon();
        $rows = $model->getList($where);
        $data = Db::name('emoticon_category')->where('status',1)->select();
        $this->assign([
            'title'=> '表情列表',
            'data'=>$data,
            'pageHTML'=>$rows->render(),
            'rows'=>$rows
        ]);
        return view();
    }

    public function edit()
    {
        if(request()->isPost()){
            $data   = input('post.');
            $model  = new Logic();
            $result = $model->saveChange('emoticon',$data,'emotion');
            if($result !== false){
                $this->success('修改成功',url('index'));
            }
            $this->error($model->getError());
        }
        $where['status'] = 1;
        $this->_show('emoticon','id','emoticon_category','',$where);
        $this->assign('title','表情编辑');
        return view();
    }


    public function del()
    {
        $this->_del('emoticon');
    }

    public function cate()
    {
        $this->_list2('emoticon_category','cid DESC');
        $this->assign('title','表情分类');
        return view();
    }


    public function cate_edit()
    {
        $this->_edit('emoticon_category','表情分类编辑',url('cate'),'emotion_category');
        return view();
    }



    public function cate_delete()
    {
       $this->_del('emoticon_category');
    }



}
